Add save-pants-cache companion action for cancellation-safe cache saves#48
Open
Affanmir wants to merge 1 commit intopantsbuild:mainfrom
Open
Add save-pants-cache companion action for cancellation-safe cache saves#48Affanmir wants to merge 1 commit intopantsbuild:mainfrom
Affanmir wants to merge 1 commit intopantsbuild:mainfrom
Conversation
BREAKING: init-pants now restores caches only (actions/cache/restore). Add pantsbuild/actions/save-pants-cache with if: always() at the end of your job to persist caches. This ensures saves survive workflow cancellation (cancel-in-progress: true), which post-step hooks do not. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0cdbb04 to
89a00ce
Compare
Contributor
|
It's probably a bad idea to break all the existing users by making the existing action not save the cache. Plus that usage snippet is very verbose, since we have to set up all those paths. Is it possible to have an optional save action, and it only runs if the earlier job was cancelled? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BREAKING:
init-pantsnow restores caches only (viaactions/cache/restore@v5). A newsave-pants-cachecompanion action must be added at the end of the job to persist caches.Why:
actions/cache@v5saves via a post-step hook that does not run on workflow cancellation. Workflows usingcancel-in-progress: trueenter a cold-cache cycle — every cancelled run loses its cache save, so the next run starts cold.Fix: Split restore and save into separate actions. The save step uses
if: always()which fires even on cancellation, breaking the cycle.Changes
init-pants/action.yaml— Switchactions/cache@v5→actions/cache/restore@v5, add outputs for cache keys/pathssave-pants-cache/action.yaml— New companion action usingactions/cache/save@v5Usage
Context
Discovered in CI where persistent cold caches occurred despite no code changes between runs. GHA cache keys are immutable, so
actions/cache/saveis a safe no-op when the key already exists.Test plan
init-pantsrestores caches correctly (setup, named, LMDB)save-pants-cachewithif: always()saves caches on normal completioncancel-in-progresscancellation